﻿using System;
using System.Collections.Generic;
using System.Text;
using Xeno.Module;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using Xeno.GUI;
using OpenTK.Math;
using Xeno.Physics;
namespace Xeno.Core
{
    public class XenoFactory
    {
        public class Physics
        {
            public static void Mesh(XenoNode node)
            {
                node.AddModule = new XenoMeshCollider(node.Name + "_MeshCollider", node);
            }
            public static void Cube(XenoNode node,float mass)
            {
                bool isStatic = false;
                if (mass < 0.0001)
                {
                    isStatic = true;
                }
                //if (!isStatic)
                
                    XenoBoxCollider cod = new XenoBoxCollider(node.Name + "_Collider", node, true);
                    node.AddModule = cod;

                  
                        XenoRigidBody bod = new XenoRigidBody(node.Name + "_RigidBody", node, isStatic, mass);
                        node.AddModule = bod;
                

            }
        }
        public class Xui
        {

            public static XenoNode GraphView(string name, XenoNode parent, Vector2 pos, Vector2 siz,XenoGraph graph)
            {

                XenoNode node = XenoFactory.Node.PrepNode(name, parent);

                node.AddModule = new XuiGraphView(siz, graph);
                node.LocalPosition = new Vector3(pos.X, pos.Y, 0);

                return node;

            }

            public static XenoNode Group(string name, XenoNode parent, string title, Vector2 pos, Vector2 siz)
            {

                XenoNode node = XenoFactory.Node.PrepNode(name, parent);

                node.AddModule = new XuiGroup(siz, title);
                node.LocalPosition = new Vector3(pos.X, pos.Y, 0);

                return node;

            }
            public static XenoNode Desktop(string name, XenoNode parent)
            {
                XenoNode node = XenoFactory.Node.PrepNode(name, parent);

                node.AddModule = new XuiDesktop();

                return node;
            }
            public static XenoNode Button(string name, XenoNode parent, string text, Vector2 pos, Vector2 siz)
            {
                XenoNode node = XenoFactory.Node.PrepNode(name, parent);

                node.AddModule = new XuiButton(siz, text);
                node.LocalPosition = new Vector3(pos.X, pos.Y, 0);
                                
                return node;
            }
        }
        public class Light
        {
            public static XenoNode Directional(string name,XenoNode parent)
            {
                
                XenoNode node = XenoFactory.Node.PrepNode(name, parent);
                    
                    node.AddModule = new XenoMod_Light(XenoMod_Light.LightType.Directional);
                
                return node;

            }
        }
        public class Mesh
        {
            public static XenoNode Pyramid(XenoNode node, float size)
            {

                XenoMesh msh = node.Mesh;

                XenoDebug.AssertNull(msh, "XenoFactory.Mesh.Pyramid");

                XenoVertex[] Vertices = new XenoVertex[5];

                Vertices[0] = new XenoVertex(new Vector3(0, size, 0), new Vector3(0, 0, 0));
                Vertices[1] = new XenoVertex(new Vector3(-size, 0, -size), new Vector3(0, 1, 0));
                Vertices[2] = new XenoVertex(new Vector3(size, 0, -size), new Vector3(1, 1, 0));
                Vertices[3] = new XenoVertex(new Vector3(size, 0, size), new Vector3(1, 1, 0));
                Vertices[4] = new XenoVertex(new Vector3(-size, 0, size), new Vector3(0, 1, 0));

                XenoTriangle[] Triangles = new XenoTriangle[6];

                Triangles[0] = new XenoTriangle(0, 1, 2);
                Triangles[1] = new XenoTriangle(0, 2, 3);
                Triangles[2] = new XenoTriangle(0, 3, 4);
                Triangles[3] = new XenoTriangle(0, 4, 1);
                Triangles[4] = new XenoTriangle(1, 2, 3);
                Triangles[5] = new XenoTriangle(3, 4, 1);

                msh.AddVertices = Vertices;
                msh.AddTriangles = Triangles;

                return node;

            }
        }
        public class Node
        {
            public static XenoNode Mesh(string name, XenoNode parent)
            {
                XenoNode node = PrepNode(name, parent);

                node.AddModule = new XenoMesh();
                node.AddModule = new MeshRenderer();
                node.MeshRenderer.Material = new XenoMaterial(name + "_Material");

                return node;

            }

            public static XenoNode Camera(string name, XenoNode parent)
            {
                XenoNode node = PrepNode(name, parent);

                node.AddModule = new XenoMod_Camera();

                return node;

            }

            public static XenoNode PrepNode(string name, XenoNode parent)
            {
                XenoNode node = null;

                if (parent != null)
                {
                    node = new XenoNode(name, parent);
                }
                else
                {
                    node = new XenoNode(name);
                }
                return node;
            }



        }
    }
}
